/*
 * Filename:    DrugStoreIntgrityServiceImpl.java
 * Copyright:   2015 中国平安保险（集团）股份有限公司 版权所有
 * Company:     平安科技养老险及健康险系统开发部
 * Create at:   2015-2-12
 */
package com.paic.mhis.hcpms.evaluation.evaluationDrugStore.drugStoreIntegrity.biz.service.impl;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.paic.mhis.hcpms.evaluation.evaluationDrugStore.drugStoreIntegrity.biz.service.DrugStoreIntgrityService;
import com.paic.mhis.hcpms.evaluation.evaluationDrugStore.drugStoreIntegrity.dao.DrugStoreIntgrityDao;
import com.paic.mhis.hcpms.evaluation.evaluationOrg.evaluationIntegrity.dao.EvaluationIntegrityOrgDao;
import com.paic.mhis.hcpms.evaluation.evaluationOrg.evaluationIntegrity.dto.EvaluationOrgDTO;

@Service("drugStoreIntgrityService")
public class DrugStoreIntgrityServiceImpl implements DrugStoreIntgrityService {

	@Autowired
	private DrugStoreIntgrityDao drugStoreIntgrityDao;

	@Autowired
	private EvaluationIntegrityOrgDao evaluationIntegrityOrgDao;

	/**
	 * 定点药店诚信List查询
	 */
	@Override
	public Map<String, Object> getDrugStoreList(Map<String, Object> map) {
		// Map<String, Object> map = new HashMap<String, Object>();
		List<String> strList = new ArrayList<String>();
		// 查询总数
		int orgCount = evaluationIntegrityOrgDao.getEvaluationOrgListCount(map);
		List<EvaluationOrgDTO> orgList = null;
		if (orgCount > 0) {
			// 查询考评机构信息
			orgList = evaluationIntegrityOrgDao.getEvaluationOrgList(map);
			for (EvaluationOrgDTO dto : orgList) {
				BigDecimal bedNum = dto.getBedNum();
				if (bedNum != null && bedNum.doubleValue() > 0) {
					dto.setBedName("有");
				} else {
					dto.setBedName("无");
				}
				String orgCode = dto.getOrgCode();
				String year = dto.getEvaluationYear();
				map.put("orgCode", orgCode);
				map.put("year", year);
				// map.put("type", "01");
				// 查询考评组名称
				List<String> list = evaluationIntegrityOrgDao.getEvaluationName(map);
				// 查询考评得分及对应的考评组
				List<Map> strList1 = evaluationIntegrityOrgDao.getEvaluationScore(map);
				int i = 0;
				for (String st : list) {
					for (Map ma : strList1) {
						if (st.equals(ma.get("GROUP_NAME"))) {
							if (i == 0) {
								dto.setOne(ma.get("EVALUATION_SCROE").toString());
							}
							if (i == 1) {
								dto.setTwo(ma.get("EVALUATION_SCROE").toString());
							}
							if (i == 2) {
								dto.setThree(ma.get("EVALUATION_SCROE").toString());
							}
							if (i == 3) {
								dto.setFour(ma.get("EVALUATION_SCROE").toString());
							}
							if (i == 4) {
								dto.setFive(ma.get("EVALUATION_SCROE").toString());
							}
							if (i == 5) {
								dto.setSix(ma.get("EVALUATION_SCROE").toString());
							}
						}
					}
					i++;
				}
			}
		}
		if (null == orgList) {
			orgList = new ArrayList<EvaluationOrgDTO>();
		}
		map.put("orgList", orgList);
		map.put("orgCount", orgCount);
		return map;
	}

	/**
	 * 根据年份查询当前需要展示的考评得分名称集合
	 * 
	 * @return
	 */
	@Override
	public List<String> getEvaluationName(String year, String type) {
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("year", year);
		map.put("type", type);
		return evaluationIntegrityOrgDao.getEvaluationName(map);
	}

}
